import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';

const Item = styled.li`
    position: relative;
    padding-left:70px;
    line-height: 20px;
    &:last-child {
        .info {
            border-bottom: none;
        }
    }
    img {
        width: 50px;
        height: 50px;
        border-radius: 25px;
        position: absolute;
        left: 10px;
        top: 10px;      
    }
    p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .info {
        border-bottom: 1px solid #ddd;
        padding: 10px 10px 10px 0;
    }
    .time {
        position: absolute;
        right: 10px;
        top: 20px;
        color: #aaa;
        font-size: 12px;
    }
    .name {
        font-size: 14px;
        color: #000;
        padding-right: 50px;
        padding-top: 10px;
    }
    .message {
        font-size: 12px;
        color: #aaa;
    }
`

export default function ContactItem(props) {
    return (
        <Item>
            <Link to={{pathname: `/chat/${props.group ? 'group' : 'person'}/${props.id}`, state: {name: props.username, avatar: props.avatar}}}>
                <img src='http://www.qqzhi.com/uploadpic/2015-01-22/073441407.jpg'/>
                <div className='info'>
                    <p className='name'>{props.username}</p>
                    <p className='message'>{props.content}</p>
                    <span className='time'>{props.time}</span>
                </div> 
            </Link>
        </Item>
    )
}
